// components/shopzujian/shopzujian.js
Component({
  lifetimes: {
    attached() { //组件的生命周期函数 页面加载的时候触发
      console.log(this.properties.tabs);
      this.setData({
        tabs: this.properties.tabs
      })
    }
  },
  /**
   * 组件的属性列表
   */
  properties: {
    tabs: {
      type: Array,
      value: []
    },
    shoplist: {
      type: Array,
      value: []
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    shoplist: [],
    tabs: [],
    blo:""
  },

  /**
   * 组件的方法列表
   */
  methods: {
    clickme(e) {
      let id = e.target.dataset.id
      let shoplist = []
      let shop = this.data.shoplist
      this.triggerEvent("aaa", id)
      this.setData({
        shoplist: this.properties.shoplist
      })
      if(this.properties.tabs[0].isactive==true){
        this.triggerEvent("eee",this.properties.tabs)
      }
      if (this.properties.tabs[2].isactive == true) {
        for (var i = 0; i < shop.length; i++) { //价格排序
          for (const key in shop[i]) {
            shop.sort(function (a, b) {
              if (a.goods_price === b.goods_price) { //如果id相同，按照age的降序
                return b.key - a.key
              } else {
                return a.goods_price - b.goods_price
              }
            })
          }
        }
      }
      this.triggerEvent("bbb", shop)
    },
    sheng(){

      this.data.blo=true
      this.triggerEvent("ddd",this.data.blo)
      let shop = this.data.shoplist
      for (var i = 0; i < shop.length; i++) { //价格排序
        for (const key in shop[i]) {
          shop.sort(function (a, b) {
            if (b.goods_price === a.goods_price) { //如果id相同，按照age的降序
              return a.key - b.key
            } else {
              return b.goods_price - a.goods_price
            }
          })
        }
      }
      this.triggerEvent("bbb", shop)
    },
    jiang(){
      let shop = this.data.shoplist
      for(var i=0;i<shop.length;i++){ //价格排序
        for (const key in shop[i]) {
          shop.sort(function(a,b){
            　　if(a.goods_price === b.goods_price){//如果id相同，按照age的降序
            　　　　return b.key - a.key
            　　}else{
            　　　　return a.goods_price - b.goods_price
            　　}
            })
        }
      }
      this.triggerEvent("bbb", shop)
  }
}
})